package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.dao.Course2Dao;
import com.example.demo.entity.Course;
import com.example.demo.entity.Course2;
import com.example.demo.service.Course2Service;
import com.example.demo.service.CourseService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * (Course2)表服务实现类
 *
 * @author makejava
 * @since 2021-03-05 16:24:56
 */
@Service("course2Service")
public class Course2ServiceImpl extends ServiceImpl<Course2Dao, Course2> implements Course2Service {

    @Resource
    Course2Service course2Service;
    @Resource
    CourseService courseService;

    @Override
    public Map<String, String> getCourses(String name,String kch_id,String xkkz_id) throws Exception {
        Course2 course2= new Course2();
        Course2 course = course2Service.getByName(name);
        Map<String,String> courses = new HashMap<>();
        // 获取对象属性
        Field[] fields = course.getClass().getDeclaredFields();
        for(Field field : fields){
            field.setAccessible(true);
            courses.put(field.getName(),field.get(course).toString());
        }
        return courses;
    }

    @Override
    public Course2 getByName(String name) {
        QueryWrapper<Course2> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name",name);
        return course2Service.getOne(queryWrapper,false);
    }

    @Override
    public Course2 getCourse2(String name, CourseService courseService, String kch_id, String xkkz_id) {
        Course course = courseService.getByName(name);
        Course2 course2 = new Course2();
        BeanUtils.copyProperties(course,course2);
//        course2.setRwlx(course.getRwlx());
//        course2.setXkly(course.getXkly());
//        course2.setBklx_id(); = course.getBklx_id();
//        course2.setXqh_id(); = course.getXqh_id();
//        course2.setJg_id(); = course.getJg_id();
//        course2.setZyh_id(); = course.getZyh_id();
//        course2.setZyfx_id(); = course.getZyfx_id();
//        course2.setNjdm_id(); = course.getNjdm_id();
//        course2.setBh_id(); = course.getBh_id();
//        course2.setXbm(); = course.getXbm();
//        course2.setXslbdm(); = course.getXslbdm();
//        course2.setCcdm();= course.getCcdm();
//        course2.setXsbj();= course.getXsbj();
//        course2.setSfkknj(); = course.getSfkknj();
//        course2.setSfkkzy(); = course.getSfkkzy();
//        course2.setSfznkx(); = course.getSfznkx();
//        course2.setZdkxms(); = course.getZdkxms();
//        course2.setsfkxq = course.getSfkxq();
//        course2.setsfkcfx = course.getSfkcfx();
//        course2.setkkbk = course.getKkbk();
//        course2.setkkbkdj = course.getKkbkdj();
//        course2.setxkxnm = course.getXkxnm();
//        course2.setxkxqm = course.getXkxqm();
//        course2.setrlkz = course.getRlkz();
//        course2.setkklxdm = course.getKklxdm();
        course2.setKch_id(kch_id);
        course2.setXkkz_id(xkkz_id);
        course2.setCxbj("0");
        course2.setFxbj("0");
        return course2;
    }
}